Selection Sort
Traversal in Binary Tree:
在遍歷一數列的時候,依據 Minimum 運算條件(ex.Math.min(nums)),
將最小值放置最左邊,並完成運算後的排序。
ex.升冪降冪排序可依運算條件決定。
Input: nums = [1, 2, 3, 2, 1, 6]
let selectionSort = (nums) => {
let newNums = []
let long = nums.length
for (let i = 0; i < long; i++) {
let min = Math.min(...nums)
newNums[i] = min
nums.splice((nums.indexOf(Math.min(...nums))), 1)
}
return newNums
};
Output: newNums = [1, 1, 2, 2, 3, 6]
Flow Chart:
[ 1 ]
[ 1, 1 ]
[ 1, 1, 2 ]
[ 1, 1, 2, 2 ]
[ 1, 1, 2, 2, 3 ]
[ 1, 1, 2, 2, 3, 6 ]
Blog:http://52.198.119.162/關於selection-sort排序方法與示意圖/